package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.RegionPageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.RegionUpsertReqDTO;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.RegionResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Autowired
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务的分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.findByPage(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("进行区域的服务新增")
    public Result add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {
        serveService.add(serveUpsertReqDTOList);
        return Result.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation("修改区域价格")
    public Result updatePriceById(@PathVariable("id") Long id, BigDecimal price) {
        log.info("id={}, price = {}", id, price);
        serveService.updateById(new Serve().setPrice(price).setId(id));
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除区域价格")
    public Result deleteById(@PathVariable("id") Long id) {
        serveService.deleteById(id);
        return Result.ok();
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("上架服务")
    public Result changeSaleStatusToUp(@PathVariable("id") Long id) {
        serveService.changeSaleStatusToUp(id);
        return Result.ok();
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("下架服务")
    public Result changeSaleStatusToDown(@PathVariable("id") Long id) {
        serveService.changeSaleStatusToDown(id);
        return Result.ok();
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("把区域中的服务设置为热门")
    public Result changeHotToOn(@PathVariable("id") Long id) {
        serveService.changeHotToOn(id);
        return Result.ok();
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("把区域中的服务设置为热门")
    public Result changeHotToOff(@PathVariable("id") Long id) {
        serveService.changeHotToOff(id);
        return Result.ok();
    }
}
